/**
 * org.vz.product.vserv.pf.impl
 * @since : jdk 1.8
 */
package org.vz.product.vserv.pf.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.vz.product.vserv.pf.dao.ReceivedSerOvershootCountDao;
import org.vz.product.vserv.pf.domain.ReceivedSerCount;
import org.vz.product.vserv.pf.domain.result.ReceivedSerOvershootCountResult;
import org.vz.product.vserv.pf.service.ReceivedSerOvershootCountService;

/**
 * @author morik is Yongxu.Wang 获取时间段服务异超负载总数
 * @CreateTime 2017年12月05日 16:46:14
 * @version 1.0.0
 * @description 
 */
@Service
public class ReceivedSerOvershootCountServiceImpl implements
		ReceivedSerOvershootCountService {
	@Autowired
	ReceivedSerOvershootCountDao receivedSerOvershootCountDao;

	@Override
	public ReceivedSerOvershootCountResult receivedSerOvershootCountService(
			String startTime, String endTime, long overShoot) {
		ReceivedSerOvershootCountResult rsocr = new ReceivedSerOvershootCountResult();
		Map<String, String> prmgr = new HashMap<String, String>();
		prmgr.put("startTime", startTime);
		prmgr.put("endTime", endTime);
		List<ReceivedSerCount> data = receivedSerOvershootCountDao
				.getSQLManager().select("seroperations.getSerUseCount",
						ReceivedSerCount.class, prmgr);
		rsocr.msg = "查询成功！！！";
		rsocr.status = 1;
		for (ReceivedSerCount receivedSerCount : data) {
			rsocr.data.tatal++;
			if (receivedSerCount.getCount() > overShoot * 0.8) {
				rsocr.data.count++;
			}
		}
		if (rsocr.data.count <= 0 || rsocr.data.tatal <= 0) {
			rsocr.data.persiont = 0;
		} else {
			rsocr.data.persiont = ((float) rsocr.data.count)
					/ ((float) rsocr.data.tatal);
		}
		return rsocr;
	}
}
